<template>
  <div>
    <TypeNav />
    <section class="heart con">
      <!-- 导航路径区域 -->
      <div class="nav-detail">
        <div class="nav-row">
          <a v-show="categoryView.category1Name">
            {{ categoryView.category1Name }}
          </a>
          <a v-show="categoryView.category2Name">
            {{ categoryView.category2Name }}
          </a>
          <a v-show="categoryView.category3Name">
            {{ categoryView.category3Name }}
          </a>
        </div>
      </div>
      <!--商品展示主要区域-->
      <div class="main-con clearfix">
        <div class="look clearfix">
          <Zoom :skuImageList="skuImageList" />
          <ImageList :skuImageList="skuImageList" />
        </div>
        <!-- 右侧选择区商品细节 -->
        <div class="details">
          <div class="goodsDetails">
            <h3 class="InfoName">
              {{ skuInfo.skuName }}
            </h3>
            <p class="news">
              {{ skuInfo.skuDesc }}
            </p>
          </div>
          <div class="price">
            <div class="price-top clearfix">
              <div class="title">价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格</div>
              <div class="price-in">
                <i>￥</i><em>{{ skuInfo.price }}</em
                ><span>降价通知</span>
              </div>
              <div class="remark">
                <i>累计评价</i>
                <em>65545</em>
              </div>
            </div>
            <div class="price-bottom">
              <div class="title">促&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;销</div>
              <div class="full-with">
                <i>加价购</i>
                <em
                  >满999.00另加20.00元，或满1999.00另加30.00元，或满2999.00另加40.00元，即可在购物车换购热销商品</em
                >
              </div>
            </div>
          </div>
          <div class="support">
            <div class="supportArea">
              <div class="title">支&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;持</div>
              <div class="fixWidth">
                以旧换新，闲置手机回收 4G套餐超值抢 礼品购
              </div>
            </div>
            <div class="supportArea">
              <div class="title">配 送 至</div>
              <div class="fixWidth">广东省 深圳市 宝安区</div>
            </div>
          </div>
          <!--选择区域-->
          <div class="choose">
            <div class="chooseArea">
              <div class="choosed clearfix">
                <div class="item">官方标配<a href="">×</a></div>
                <div class="item">金色<a href="">×</a></div>
              </div>
              <dl v-for="spuSaleAttr in spuSaleAttrList" :key="spuSaleAttr.id">
                <dt class="title">{{ spuSaleAttr.saleAttrName }}</dt>
                <dd
                  v-for="spuSaleAttrValue in spuSaleAttr.spuSaleAttrValueList"
                  :key="spuSaleAttrValue.id"
                  :class="{ active: spuSaleAttrValue.isChecked == 1 }"
                  @click="
                    changeActive(
                      spuSaleAttrValue,
                      spuSaleAttr.spuSaleAttrValueList
                    )
                  "
                >
                  {{ spuSaleAttrValue.saleAttrValueName }}
                </dd>
              </dl>
            </div>
            <div class="cart clearfix">
              <div class="cont">
                <input
                  autocomplete="off"
                  v-model="skuNum"
                  @change="changeNum"
                />
                <a class="plus" @click="skuNum++">+</a>
                <a class="min" @click="skuNum > 1 ? skuNum-- : (skuNum = 1)"
                  >-</a
                >
              </div>
              <div class="add">
                <a @click="addShopCar">加入购物车</a>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 内容详情页 -->
      <div class="productDetail clearfix">
        <aside class="left">
          <div class="tabWraped">
            <h4 class="active">相关分类</h4>
            <h4 class="">推荐品牌</h4>
          </div>
          <div class="tabContent">
            <div class="tab-in active">
              <ul class="partList clearfix">
                <li>手机</li>
                <li>手机壳</li>
                <li>手机配件</li>
                <li>钢化膜</li>
                <li>内存卡</li>
                <li>充电器</li>
                <li>电源</li>
                <li>保修</li>
              </ul>
              <ul class="goodList">
                <li>
                  <div class="list-wrap">
                    <div class="p-img">
                      <img src="./upload/good1.png" />
                    </div>
                    <div class="attr">Apple苹果iPhone 6s (A1699)</div>
                    <div class="price">
                      <em>¥</em>
                      <i>6088.00</i>
                    </div>
                    <div class="operate">
                      <a>加入购物车</a>
                    </div>
                  </div>
                </li>
                <li>
                  <div class="list-wrap">
                    <div class="p-img">
                      <img src="./upload/good1.png" />
                    </div>
                    <div class="attr">Apple苹果iPhone 6s (A1699)</div>
                    <div class="price">
                      <em>¥</em>
                      <i>6088.00</i>
                    </div>
                    <div class="operate">
                      <a>加入购物车</a>
                    </div>
                  </div>
                </li>
                <li>
                  <div class="list-wrap">
                    <div class="p-img">
                      <img src="./upload/good1.png" />
                    </div>
                    <div class="attr">Apple苹果iPhone 6s (A1699)</div>
                    <div class="price">
                      <em>¥</em>
                      <i>6088.00</i>
                    </div>
                    <div class="operate">
                      <a>加入购物车</a>
                    </div>
                  </div>
                </li>
              </ul>
            </div>
            <div class="tab-in">推荐品牌</div>
          </div>
        </aside>
        <div class="right">
          <div class="fitting">
            <h4 class="kt">选择搭配</h4>
            <div class="good-fit clearfix">
              <div class="master">
                <img src="./upload/good1.png" />
                <p>￥5299</p>
                <i>+</i>
              </div>
              <ul class="suits">
                <li>
                  <img src="./upload/good2.png" alt="图片加载失败" />
                  <p>相关手机</p>
                  <label>
                    <input type="checkbox" value="39" />
                    <span>39</span>
                  </label>
                </li>
                <li>
                  <img src="./upload/good2.png" alt="图片加载失败" />
                  <p>相关手机</p>
                  <label>
                    <input type="checkbox" value="39" />
                    <span>59</span>
                  </label>
                </li>
                <li>
                  <img src="./upload/good2.png" alt="图片加载失败" />
                  <p>相关手机</p>
                  <label>
                    <input type="checkbox" value="39" />
                    <span>89</span>
                  </label>
                </li>
                <li>
                  <img src="./upload/good2.png" alt="图片加载失败" />
                  <p>相关手机</p>
                  <label>
                    <input type="checkbox" value="39" />
                    <span>39</span>
                  </label>
                </li>
              </ul>
              <div class="result">
                <div class="num">已选购0件商品</div>
                <div class="price-tit">套餐价</div>
                <div class="price">¥5299</div>
                <button class="addshopcar">加入购物车</button>
              </div>
            </div>
          </div>
          <div class="info clearfix">
            <ul class="tab-wraped">
              <li class="active"><a>商品介绍</a></li>
              <li><a>规格与包装</a></li>
              <li><a>售后保障</a></li>
              <li><a>社区</a></li>
              <li><a>买家评价</a></li>
            </ul>
            <div class="tab-content active">
              <ul class="goods-intro">
                <li>分辨率：1920*1080(FHD)</li>
                <li>后置摄像头：1200万像素</li>
                <li>前置摄像头：500万像素</li>
                <li>核 数：其他</li>
                <li>频 率：以官网信息为准</li>
                <li>品牌： Apple</li>
                <li>商品名称：APPLEiPhone 6s Plus</li>
                <li>商品编号：1861098</li>
                <li>商品毛重：0.51kg</li>
                <li>商品产地：中国大陆</li>
                <li>热点：指纹识别，Apple Pay，金属机身，拍照神器</li>
                <li>系统：苹果（IOS）</li>
                <li>像素：1000-1600万</li>
                <li>机身内存：64GB</li>
              </ul>
              <div class="intro-detail">
                <img
                  v-for="imgSrc in skuImageList.slice(0, 2)"
                  :key="imgSrc.id"
                  :src="imgSrc.imgUrl"
                  style="height: 800px; width: 800px; margin: 0 100px"
                />
              </div>
            </div>
            <div class="tab-content">1111</div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import ImageList from "./ImageList";
import Zoom from "./Zoom";
import { mapGetters } from "vuex";
export default {
  name: "Detail",
  components: { ImageList, Zoom },
  mounted() {
    this.$store.dispatch("getGoodsInfo", this.$route.params.skuid);
  },
  computed: {
    ...mapGetters(["categoryView", "skuInfo", "spuSaleAttrList"]),
    skuImageList() {
      return this.skuInfo.skuImageList || [];
    },
  },
  methods: {
    //产品属性选择高亮改变
    changeActive(spuSaleAttrValue, arr) {
      //排他法
      arr.forEach((item) => {
        item.isChecked = "0";
      });
      spuSaleAttrValue.isChecked = "1";
    },
    changeNum(event) {
      let value = event.target.value * 1;
      if (isNaN(value) || value < 1) {
        this.skuNum = 1;
      } else {
        this.skuNum = parseInt(value);
      }
    },
    async addShopCar() {
      try {
        await this.$store.dispatch("addOrUpdateShopCart", {
          skuId: this.$route.params.skuid,
          skuNum: this.skuNum,
        });
        sessionStorage.setItem("SKUINFO", JSON.stringify(this.skuInfo));
        this.$store.dispatch("getCartList");
        this.$router.push({
          name: "addcartsuccess",
          query: { skuNum: this.skuNum },
        });
      } catch (error) {
        alert(error.message);
      }
    },
  },
  data() {
    return {
      skuNum: 1,
    };
  },
};
</script>

<style lang="css" scoped>
.look {
  float: left;
  width: 400px;
}
.con {
  min-height: 1000px;
}
.con .nav-detail {
  height: auto;
  width: 100%;
  padding: 25px 15px 9px 0;
}
.con .nav-detail .nav-row {
  padding: 3px 0px;
}
.con .nav-detail .nav-row a {
  position: relative;
  display: inline-block;
  padding-right: 15px;
}
.con .nav-detail .nav-row a:hover {
  color: #666;
  text-decoration-line: underline;
}
.con .nav-detail .nav-row a::before {
  position: absolute;
  content: "/";
  top: 0;
  left: -10px;
  color: #ccc;
}
.con .nav-detail .nav-row a:first-child::before {
  content: "";
}
.main-con {
  width: 100%;
  min-height: 200px;
  overflow: hidden;
}
img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/*右侧选择区域布局*/
.main-con .details {
  float: right;
  width: 700px;
}
.main-con .details .goodDetails {
  display: block;
}
h3[class="InfoName"] {
  display: block;
  font-size: 14px;
  line-height: 21px;
  margin-top: 15px;
  color: rgb(72, 70, 70);
}
p[class="news"] {
  color: #d43036;
  margin-top: 15px;
}
.main-con .details .price {
  background: #fee9eb;
  padding: 7px;
  margin: 13px 0;
}
.main-con .details .price-top {
  margin-top: 10px;
  line-height: 28px;
}
.main-con .details .title {
  float: left;
  margin-right: 15px;
}
.main-con .details .price-top .price-in {
  float: left;
  color: #e42532;
}
.main-con .details .price-top .price-in i {
  font-size: 16px;
}
.main-con .details .price-top .price-in em {
  font-weight: 700;
  font-size: 24px;
}
.main-con .details .price-top .price-in span {
  font-size: 12px;
}
.main-con .details .price-top .remark {
  float: right;
}
.main-con .details .price-bottom {
  overflow: hidden;
  line-height: 28px;
  margin-top: 10px;
}
.main-con .details .price-bottom .full-with {
  float: left;
  width: 520px;
}
.main-con .details .price-bottom .full-with i {
  display: inline-block;
  padding: 0 3px;
  background-color: #e42532;
  line-height: 22px;
  color: #fff;
}
.main-con .details .price-bottom .full-with em {
  color: #999;
}
.details .support {
  border-bottom: 1px solid #ededed;
}
.details .support .supportArea {
  overflow: hidden;
  line-height: 28px;
  margin-top: 10px;
}
.details .support .title {
  margin-right: 15px;
  float: left;
}
.details .support .fixWidth {
  width: 520px;
  float: left;
  color: #999;
}
.details .choose .chooseArea {
  overflow: hidden;
  line-height: 28px;
  margin-top: 10px;
}
.details .choose .chooseArea .choosed {
  display: block;
}
.details .choose .chooseArea .choosed .item {
  float: left;
  height: 32px;
  padding: 0 15px;
  border: 1px solid #ddd;
  margin-right: 10px;
  line-height: 30px;
  background-color: snow;
}
.details .choose .chooseArea .choosed .item a {
  display: inline-block;
  padding-left: 15px;
  font-size: 12px;
  color: #e42532;
}
.details .choose dl {
  float: left;
  width: 700px;
  overflow: hidden;
  margin: 8px 0;
}
.details .choose dl dd {
  float: left;
  margin-right: 5px;
  color: #666;
  line-height: 24px;
  padding: 2px 14px;
  border-top: 1px solid #eee;
  border-right: 1px solid #bbb;
  border-bottom: 1px solid #bbb;
  border-left: 1px solid #eee;
}
.details .choose dl dd:hover {
  cursor: pointer;
  color: #e42532;
}
.details .choose dl dd[class="active"] {
  color: #e42532;
  border-bottom: 1px solid #e42532;
  border-right: 1px solid #e42532;
  border-left: 1px solid rgb(255, 197, 197);
  border-top: 1px solid rgb(255, 197, 197);
}
.details .choose dl dt {
  float: left;
  margin-right: 15px;
  line-height: 30px;
}
.choose .cart {
  margin-top: 5px;
}
.choose .cart .cont {
  float: left;
  width: 60px;
  height: 40px;
  margin-right: 8px;
}
.choose .cart .cont input {
  display: block;
  float: left;
  width: 40px;
  height: 40px;
  text-align: center;
  border: 1px solid #ddd;
  color: #555;
}
.choose .cart .cont a {
  display: block;
  float: left;
  width: 20px;
  height: 20px;
  text-align: center;
  background: #f1f1f1;
  color: #666;
  border: 1px solid #ccc;
  border-left: none;
}
.choose .cart .cont a:hover {
  cursor: pointer;
}
.choose .cart .add {
  float: left;
}
.choose .cart .add a {
  display: block;
  height: 40px;
  padding: 0 25px;
  background-color: #e42532;
  font-size: 16px;
  line-height: 40px;
  color: #fff;
}
.choose .cart .add a:hover {
  cursor: pointer;
}
/*内容详情页*/
.productDetail {
  height: auto;
  margin: 30px 0 15px 0;
}
.productDetail .left {
  width: 210px;
  min-height: 200px;
  float: left;
  border: 1px solid #ccc;
}
.productDetail .left .tabWraped {
  width: 100%;
  height: 40px;
}
.productDetail .left .tabWraped h4 {
  border-top: 3px solid #fff;
  float: left;
  line-height: 37px;
  width: 50%;
  height: 100%;
  text-align: center;
  border-bottom: 1px solid #ccc;
}
.productDetail .left .tabWraped h4:hover {
  cursor: pointer;
}
.productDetail .left .tabWraped .active {
  border-top: 3px solid #e42532;
  border-bottom: none;
  font-weight: 400;
}
.productDetail .left .tabContent {
  width: 100%;
  padding: 10px;
}
.productDetail .left .tabContent .tab-in {
  display: none;
}
.productDetail .left .tabContent .active {
  display: block;
}
.productDetail .left .tabContent .tab-in .partList {
  display: block;
}
.productDetail .left .tabContent .tab-in .partList li {
  width: 50%;
  float: left;
  border-bottom: 1px dashed #ededed;
  line-height: 28px;
}
.productDetail .left .tabContent .tab-in .goodList {
  display: block;
}
.productDetail .left .tabContent .tab-in .goodList > li {
  width: 100%;
  margin: 5px 0 15px;
  border-bottom: 1px solid #ededed;
  padding-bottom: 5px;
}
.productDetail .left .tabContent .tab-in .goodList > li .p-img {
  text-align: center;
}
.productDetail .left .tabContent .tab-in .goodList > li .price {
  font-size: 16px;
  color: #c81623;
}
.productDetail .left .tabContent .tab-in .goodList > li .operate {
  text-align: center;
  margin: 5px 0;
}
.productDetail .left .tabContent .tab-in .goodList > li .operate a {
  display: inline-block;
  cursor: pointer;
  border: 1px solid #8c8c8c;
  color: #8c8c8c;
  padding: 2px 14px;
  line-height: 18px;
}
.productDetail .left .tabContent .tab-in .goodList > li .operate a:hover {
  color: #e42532;
}
/*右详情*/
.productDetail .right {
  width: 980px;
  min-height: 200px;
  float: right;
}
.productDetail .right .fitting {
  border: 1px solid #ddd;
  margin-bottom: 15px;
}
.productDetail .right .fitting .kt {
  border-bottom: 1px solid #ddd;
  background: #f1f1f1;
  color: #333;
  padding: 5px 0 5px 15px;
}
.productDetail .right .fitting .good-fit {
  padding-top: 10px;
}
.productDetail .right .fitting .good-fit .master {
  position: relative;
  float: left;
  width: 127px;
  height: 165px;
  text-align: center;
  margin-bottom: 10px;
  margin-right: 30px;
}
.productDetail .right .fitting .good-fit img {
  width: 120px;
  height: 130px;
}
.productDetail .right .fitting .good-fit .master p {
  color: #c81623;
  font-size: 16px;
  font-weight: 700;
}
.productDetail .right .fitting .good-fit .master i {
  position: absolute;
  top: 55px;
  right: -25px;
  font-size: 16px;
}
.productDetail .right .fitting .good-fit .suits {
  float: left;
  height: 165px;
  text-align: center;
  margin-bottom: 10px;
}
.productDetail .right .fitting .good-fit .suits li {
  float: left;
  width: 127px;
  margin-right: 20px;
}
label input,
label span {
  vertical-align: middle;
}
.good-fit .result {
  float: left;
  border-left: 1px solid #ddd;
  padding-left: 35px;
  width: 185px;
  height: 165px;
}
.good-fit .result .num {
  font-size: 14px;
  margin-bottom: 10px;
  margin-top: 10px;
}
.good-fit .result .price-tit {
  font-weight: bold;
  margin-bottom: 10px;
  color: #333;
}
.good-fit .result .price {
  color: #e42532;
  font-size: 16px;
  margin-bottom: 10px;
}
.good-fit .result .addshopcar {
  padding: 10px 25px;
  font-size: 16px;
  color: #fff;
  display: inline-block;
  background-color: #e42532;
}
.right .info .tab-wraped {
  background: #e4e4e4;
  overflow: hidden;
}
.right .info .tab-wraped li {
  float: left;
}
.right .info .tab-wraped li a {
  display: block;
  float: left;
  height: 40px;
  line-height: 40px;
  padding: 0 15px;
  text-align: center;
  background: #fcfcfc;
  border: 1px solid #ddd;
  border-right: none;
  cursor: pointer;
}
.right .info .tab-wraped li[class="active"] a {
  background-color: #e42532;
  color: #fff;
}
.right .info div[class="tab-content active"] {
  display: block;
}
.right .info div[class="tab-content"] {
  display: none;
}
.right .info .tab-content .goods-intro li {
  padding-top: 10px;
  padding-left: 10px;
}
/*侧边栏部分*/
.toolbar {
  background-color: #8c8c8c;
  position: fixed;
  width: 300px;
  height: 100%;
  z-index: 2;
  right: 0;
  top: 0;
}
.toolbar .content {
  position: relative;
  background-color: pink;
  height: 100%;
  left: 6px;
  width: 294px;
  z-index: 88;
}
.toolbar .but {
  position: absolute;
  background-image: url("./upload/cross.png");
  background-repeat: no-repeat;
  background-size: cover;
  background-color: #8c8c8c;
  width: 35px;
  height: 35px;
  z-index: 99;
  top: 0;
  left: -29px;
  border-radius: 4px 0 0 4px;
  cursor: pointer;
}
.toolbar .toolist {
  position: absolute;
  top: 50%;
  left: -29px;
  transform: translate(0, -50%);
}
.toolbar .pull {
  width: 35px;
  height: 35px;
  margin-bottom: 1px;
  cursor: pointer;
  border-radius: 4px 0 0 4px;
  text-align: center;
}
.toolbar .pull .tab-ico {
  display: inline-block;
  width: 35px;
  height: 35px;
  background-color: #8c8c8c;
  background-image: url("./upload/toolbars.png");
  border-radius: 4px 0 0 4px;
}
.toolbar .pull .tab-ico.vip {
  background-position: -88px -175px;
}
.toolbar .pull .tab-ico.cart {
  background-position: -50px 0;
}
.toolbar .pull .tab-ico.follow {
  background-position: -50px -50px;
}
.toolbar .pull .tab-ico.history {
  background-position: -50px -100px;
}
.toolbar .pull .tab-ico.message {
  background-position: -190px -150px;
}
.toolbar .pull .tab-ico.jimi {
  background-position: -50px -150px;
}
.toolbar .pull .tab-ico.top {
  background-position: -50px -250px;
}
.toolbar .pull .tab-text {
  position: absolute;
  width: 62px;
  height: 35px;
  line-height: 35px;
  color: #fff;
  text-align: center;
  border-radius: 3px 0 0 3px;
  background-color: #8c8c8c;
  left: 35px;
  z-index: 1;
}
.toolbar .pull .tab-ico:hover,
.toolbar .pull .tab-text:hover {
  background-color: #e42532;
}
.toolbar .back {
  position: absolute;
  bottom: 0;
  left: -29px;
}
</style>
